package com.ruoyi.common.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池管理
 * 无界corePoolsize,0sizeBlockingQueue，适用于CPU密集型任务调度
 */
public class ThreadPoolManager {

	private ExecutorService service;

	private ThreadPoolManager() {
		service = Executors.newCachedThreadPool();
	}

	private static volatile ThreadPoolManager manager;

	public static ThreadPoolManager getInstance() {
		if (null == manager) {
			synchronized (ThreadPoolManager.class) {
				if (null == manager) {
					manager = new ThreadPoolManager();
				}
			}
		}

		return manager;
	}

	public void addTask(Runnable runnable) {
		service.submit(runnable);
	}
}
